package com.xh.mybatisplus.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;
import java.util.Date;

/**
 * @program: xh-learn-record
 * @description:
 * @author: sch
 * @create: 2023-02-28 16:34
 **/
@RestController
@RequestMapping("redistest")
public class RedisTestController {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @RequestMapping("get")
    public String get(String str){
        return stringRedisTemplate.opsForValue().get(str);
    }

    @RequestMapping("set")
    public String get(String str,String val){
        stringRedisTemplate.opsForValue().set(str,val);
        return "ok";
    }

    @RequestMapping("lockTest")
    public String lockTest(){
        String key = "lock001";
        //加锁
//        DistributedRedisLock.acquire(key);
        //执行具体业务逻辑
//        dosoming
        //释放锁
//        DistributedRedisLock.release(key);
        //返回结果
        return "ok";
    }



}
